﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace T2G_menu_generator
{
    public partial class Form1 : Form
    {
    	private SQLiteDatabase test;
        private String rootName = "UNI";
        private String dbFileName = "T2G_reports.db3";

        public Form1()
        {
            InitializeComponent();
            DataConnect();
            InitializeTree();
        }

        private void InitializeTree()
        {
            treeView1.Nodes.Add(rootName);
        }

        private void DataConnect()
        {
        	test = new SQLiteDatabase(dbFileName);
        	
            string createTableVersion = @"CREATE TABLE IF NOT EXISTS [version] (
                          [id_version] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                          [identifier] NVARCHAR(128) NULL,
                          [description] NVARCHAR(1024) NULL,
                          [directory] NVARCHAR(1024) NULL,
                          [x_created] DATETIME DEFAULT CURRENT_TIMESTAMP
                          )";

            string createTableReport = @"CREATE TABLE IF NOT EXISTS [report] (
                          [id_report] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                          [identifier] NVARCHAR(128) NULL,
                          [description] NVARCHAR(1024) NULL,
                          [filename] NVARCHAR(1024) NULL,
                          [x_created] DATETIME DEFAULT CURRENT_TIMESTAMP
                          )";

            string createTableParameter = @"CREATE TABLE IF NOT EXISTS [parameter] (
                          [id_parameter] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                          [identifier] NVARCHAR(128) NULL,
                          [description] NVARCHAR(1024) NULL,
                          [note] NVARCHAR(1024) NULL,
                          [value] NVARCHAR(1024) NULL,
                          [type_name] NVARCHAR(128) NULL,
                          [x_created] DATETIME DEFAULT CURRENT_TIMESTAMP
                          )";

            if (!File.Exists(dbFileName))
            {
                System.Data.SQLite.SQLiteConnection.CreateFile("T2G_reports.db3");        // Create the file which will be hosting our database
            }
            
            test.ExecuteNonQuery(createTableVersion);
            test.ExecuteNonQuery(createTableReport);
            test.ExecuteNonQuery(createTableParameter);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataConnect();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
/*
            XDocument doc = XDocument.Load("XMLFile1.xml");

            var authors = doc.Descendants("Author");

            foreach (var author in authors)
            {
                Console.WriteLine(author.Value);
            }
            Console.ReadLine();
*/
            if (MessageBox.Show("Exit application ?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) Application.Exit();
        }
    }
}
